﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;

namespace StickTops
{
    public partial class MainForm : Form
    {
       private Point LastCursorPosition;
       private bool IsMouseDown = false;
       ArrayList StickTopList = new ArrayList();

        public MainForm()
        {
            InitializeComponent();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            if (CheckConnection() == false)
            {
                MessageBox.Show("Could not connect to the server");
            }
            else MessageBox.Show("Connection Established!");

        }

        /// <summary>
        /// Make new Note Form
        /// </summary>
        /// <param name="label">The label of the new note form</param>
        public void MakeNewNote(string label)
        {

            StickTop CurrentStick = new StickTop(label, this);
            CurrentStick.Show();
            StickTopList.Add(CurrentStick);
            
        }

        private void NewIconMenuItem_Click(object sender, EventArgs e)
        {
            MakeNewNote("NoName");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        /// <summary>
        /// Check if the connection to the sql server works
        /// </summary>
        /// <returns>true if it can connect else false</returns>
        public Boolean CheckConnection()
        {
            System.Data.SqlClient.SqlConnection SqlConn = new System.Data.SqlClient.SqlConnection(@"Data Source=JEREMISDATOR\SQLEXPRESS;Initial Catalog=StickTops;Integrated Security=True");
            Boolean works;

            try
            {
                SqlConn.Open();
                if (SqlConn.State == ConnectionState.Open) works = true; else works = false;
            }
            finally { SqlConn.Close(); }

            if (works == true) return true; else return false;

        }


        private void button1_Click(object sender, EventArgs e)
        {
            //login or make account if username does not exsist
        }

        private void textBox2_Enter(object sender, EventArgs e)
        {
            //  Check if the username exsist or not and print it out on label3
        }


#region "Move Form"



        private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = true;
            this.LastCursorPosition = new Point(e.X, e.Y);
        }

        private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = false;
        }

        private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsMouseDown == true)
            {
                //Move the form
                this.Location = new Point(this.Left - (this.LastCursorPosition.X - e.X), this.Top - (this.LastCursorPosition.Y - e.Y));

                //Redraw the form//
                this.Invalidate();
            }

        }

        private void pictureBox9_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsMouseDown == true)
            {
                //Move the form
                this.Location = new Point(this.Left - (this.LastCursorPosition.X - e.X), this.Top - (this.LastCursorPosition.Y - e.Y));

                //Redraw the form//
                this.Invalidate();
            }

        }

        private void pictureBox9_MouseDown(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = true;
            this.LastCursorPosition = new Point(e.X, e.Y);
        }

        private void pictureBox9_MouseUp(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = false;
        }

        private void pictureBox3_MouseUp(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = false;
        }

        private void pictureBox3_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsMouseDown == true)
            {
                //Move the form
                this.Location = new Point(this.Left - (this.LastCursorPosition.X - e.X), this.Top - (this.LastCursorPosition.Y - e.Y));

                //Redraw the form//
                this.Invalidate();
            }

        }

        private void pictureBox3_MouseDown(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = true;
            this.LastCursorPosition = new Point(e.X, e.Y);
        }

        private void pictureBox6_MouseUp(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = false;
        }

        private void pictureBox6_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsMouseDown == true)
            {
                //Move the form
                this.Location = new Point(this.Left - (this.LastCursorPosition.X - e.X), this.Top - (this.LastCursorPosition.Y - e.Y));

                //Redraw the form//
                this.Invalidate();
            }

        }

        private void pictureBox6_MouseDown(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = true;
            this.LastCursorPosition = new Point(e.X, e.Y);
        }
#endregion

        

    }
}
